#include "tools.h"
#include "emis.h"
#include <stdlib.h>
#include <getch.h>
#include"managerview_console_impl.h"
void Admin_login_check(void)
{
	system("clear");
	while(1)
	{	
		cout<<"----超级管理员登陆界面----"<<endl;
		cout<<"请输入ID：";
		int admin_id;
		cin>>admin_id;
		cout<<"请输入密码：";
		string pwd;
		cin>>pwd;
		if(admin_id == Admin_id && pwd==Admin_password)
		{
			cout<<"登陆成功"<<endl;
			mci.menu();
			return;
		}
		else
		{
			cout<<"登陆失败，ID或密码错误..."<<endl;
			stdin->_IO_read_ptr =stdin->_IO_read_end;
			getch();
			break;
		}
	}
	return;	
}	
	
	
void Delete(const char* filepath, int n)
{
	fstream file("data/manager.txt");
	string line;
	int count=0;
	ofstream outfile("in2.txt",ios::out|ios::trunc);
	while(!file.eof())
	{
	getline(file,line);
	if(count!=n-1)//如果要修改内容就在这修改line的内容,再存到文件中就行了
	outfile<<line<<endl;
	count++;
	}
	outfile.close();
	file.close();
	ofstream outfile1("data/manager.txt",ios::out|ios::trunc);
	fstream file1("in2.txt");
	while(!file1.eof())
	{
	getline(file1,line);
	outfile1<<line<<endl;
	}
	outfile1.close();
	file1.close();
	system("rm in2.txt");//删除中间文件
}
 	
#include "tools.h"
#include <string.h>
#include <getch.h>
#include <stdbool.h>

void clear_stdin(void)
{
	stdin->_IO_read_ptr = stdin->_IO_read_end;//清理输入缓冲区
}

char get_cmd(char start,char end)
{
	clear_stdin();

	printf("请输入指令:");
	while(true)
	{
		char val = getch();
		if(val >= start && val <= end)
		{
			printf("%c\n",val);
			return val;
		}
	}
}

char* get_pw(char* passwd,bool is_show,size_t size)
{
	if(NULL == passwd) return NULL;

	unsigned int count = 0;
	do{
		char val = getch();
		if(127 == val)
		{
			if(count > 0)
			{
				if(is_show)printf("\b \b");
				count--;
			}
			continue;
		}
		else if(10 == val)
		{
			break;
		}
		passwd[count++] = val;
		if(is_show) printf("*");
	}while(count < size -1);

	passwd[count] = '\0';
	return passwd;
}
	
	
	
